///////////////////////////////////////////////////////////
//  DoubleData.cpp
//  Implementation of the Class DoubleData
//  Created on:      19-Aug-2013 10:14:37 PM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#include "DoubleData.h"
#include <math.h>
#include "DataSchemaXML.h"

using namespace Data;
#define DEFDOUBLE 0.0001

DoubleData::DoubleData(const double& _value)
{
  this->m_type = IObject::DATA_T;
  this->m_dataType = IData::DOUBLE_T;
  this->m_value = _value;
}


DoubleData::DoubleData(const DoubleData& anotherDouble)
{
  this->m_type = IObject::DATA_T;
  this->m_dataType = IData::DOUBLE_T;
  this->m_value = anotherDouble.m_value;
}


DoubleData::~DoubleData()
{

}


IData::DataType DoubleData::GetDataType() const 
{

	return this->m_dataType;
}


IObject::ObjectType DoubleData::GetType() const 
{

	return this->m_type;
}


double DoubleData::GetValue() const 
{

	return this->m_value;
}


void DoubleData::SetValue(const double& _value)
{
  this->m_value = _value;
}


IObject* DoubleData::Clone()
{
  DoubleData* cloneData = new DoubleData(*this);
	return cloneData;
}


String_t DoubleData::ToString() const 
{
  StringStream_t result;
  result.precision(4);
  /*result << L"value = " << this->m_value << std::endl;*/
  result << this->m_value;
  return result.str();
  
}


String_t DoubleData::ToXML()
{
  //<UseDouble>1.2555</UseDouble>
  StringStream_t xml;
  xml.precision(4);
  xml << _T("<") << DataSchemaXML::DOUBLEDATA_ELEMENT << _T(">") << this->m_value << _T("</") << DataSchemaXML::DOUBLEDATA_ELEMENT << _T(">");
  return xml.str();
}

bool DoubleData::operator==( const double& _anotherValue ) const
{
  return fabs(this->m_value - _anotherValue) < DEFDOUBLE;
}

bool DoubleData::operator!=( const double& _anotherValue ) const
{
  return fabs(this->m_value - _anotherValue) > DEFDOUBLE;
}

bool DoubleData::operator>( const double& _anotherValue ) const
{
  return this->m_value > _anotherValue;
}

bool DoubleData::operator>=( const double& _anotherValue ) const
{
  return this->m_value >= _anotherValue;
}

bool DoubleData::operator<( const double& _anotherValue ) const
{
  return this->m_value < _anotherValue;
}

bool DoubleData::operator<=( const double& _anotherValue ) const
{
  return this->m_value <= _anotherValue;
}
